package cn.wolfcode.luowowo.search.service.impl;

import cn.wolfcode.luowowo.search.query.IndexSearchQuery;
import cn.wolfcode.luowowo.search.repository.DestinationTemplateRepository;
import cn.wolfcode.luowowo.search.repository.TravelTemplateRepository;
import cn.wolfcode.luowowo.search.service.ITravelSearchService;
import cn.wolfcode.luowowo.search.service.SearchQueryService;
import cn.wolfcode.luowowo.search.template.TravelTemplate;
import cn.wolfcode.luowowo.search.template.UserInfoTemplate;
import com.alibaba.dubbo.config.annotation.Service;
import org.elasticsearch.client.transport.TransportClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;

import java.util.List;

/**
 * @author 猫教授
 * @date 2019/8/18 17:18
 */
@Service
public class TravelSearchServiceImpl implements ITravelSearchService {
    //操作se搜索引擎的共有三个操作方式,分别con底层到上层
    //第一种,是repository接口
    @Autowired
    private TravelTemplateRepository repository;
    //第二种是template
    @Autowired
    private ElasticsearchTemplate template;
    //第三种是最底层的
    @Autowired
    private TransportClient client;
    @Autowired
    private SearchQueryService searchQueryService;

    @Override
    public void save(TravelTemplate tt) {
        repository.save(tt);
    }

    @Override
    public List<TravelTemplate> findByDestName(String keyword) {



        return repository.findByDestName(keyword);
    }

    @Override
    public AggregatedPage<TravelTemplate> selectByKeyword(IndexSearchQuery qo, String... fieldName) {


        return searchQueryService.selectByKeyword(qo,"<span style='color:red;'>","</span>",TravelTemplate.class,TravelTemplate.INDEX_NAME,TravelTemplate.TYPE_NAME,fieldName);
    }
}
